Skip to content

Conversation

@meipp
Copy link

@meipp meipp commented Sep 19, 2025

Addresses #47

@alt-romes
Copy link
Collaborator

I've rebased this on master. Looking into the segfault now.

@alt-romes
Copy link
Collaborator

The issue was evalStmt receives an EvalExpr ForeignHValue representing a IO [a] action.

With your code, if you make the method of the instance return an IO [a] action then evalStmt will find no problem in executing it:

module Main where

import qualified Data.Text as T

class Debug a where
  debugDisplayTree :: a -> IO [String]

instance Debug T.Text where
  debugDisplayTree txt = print ("Text: " ++ T.unpack txt) >> return []

f :: T.Text -> T.Text
f x = x

main :: IO ()
main = do
  print (f $ T.pack "Hello, Haskell!")

You should see what the result of debugDisplayTree being printed out only by stopping at f, because the method is being called on x!

If you look in GHC.Runtime.Interpreter you will find other functions which wrap "foreign" evaluation. They may be closer to what you intended to explore. Namely:

-- | Execute an action of type @IO ()@
evalIO :: Interp -> ForeignHValue -> IO ()
evalIO interp fhv =
  liftIO $ withForeignRef fhv $ \fhv ->
    interpCmd interp (EvalIO fhv) >>= fromEvalResult

-- | Execute an action of type @IO String@
evalString :: Interp -> ForeignHValue -> IO String
evalString interp fhv =
  liftIO $ withForeignRef fhv $ \fhv ->
    interpCmd interp (EvalString fhv) >>= fromEvalResult

-- | Execute an action of type @String -> IO String@
evalStringToIOString :: Interp -> ForeignHValue -> String -> IO String
evalStringToIOString interp fhv str =
  liftIO $ withForeignRef fhv $ \fhv ->
    interpCmd interp (EvalStringToString fhv str) >>= fromEvalResult

Feel free to keep exploring. I still haven't had the design discussion about the type class we'd want to have, at least to a first approximation.

@alt-romes
Copy link
Collaborator

alt-romes commented Oct 31, 2025

@meipp what is your status regarding your work? If you'd like, I can pick this up and finish it.

The main difficulty is designing the type class, but I've got a few ideas to try. The challenging part of calling the instance dynamically you've already figured out, so I can just re-use that for a custom class.

This is now more of a priority for the project I believe and I'd be willing/looking forward to work on this now

@meipp
Copy link
Author

meipp commented Nov 1, 2025

Still no productive update here. Can't work out the calling structure: evalStmt, evalString do SigTerm/SigAbrt. You can pick up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants